package gfx;

import util.Logger;


public class Camera {
	public static float GL_WIDTH  = 10;
	public static float GL_HEIGHT = 6;
	public static int SCREEN_WIDTH;
	public static int SCREEN_HEIGHT;
	public static float SCREEN_RATIO;

	public static final float FOVY         = 45;
	public static final float DISTANCE_MOD = (float)Math.tan(Math.toRadians(FOVY / 2));
	public static final float Z_DISTANCE   = -(GL_HEIGHT*.5f/DISTANCE_MOD);
	
	private Camera(){};

	private static class CameraHolder {
		public static final Camera instance = new Camera();
	}

	public static Camera getInstance(){
		return CameraHolder.instance;
	}

	public void setScreenSize(int width, int height){
		SCREEN_WIDTH  = width;
		SCREEN_HEIGHT = height;
		SCREEN_RATIO  = (float)width / (float)height;
	}
	
	public float getGLX(float screenX){
		return screenX * (GL_WIDTH / SCREEN_WIDTH);
	}
	
	public float getGLY(float screenY){
		return (SCREEN_HEIGHT-screenY) * (GL_HEIGHT / SCREEN_HEIGHT);
	}

	public int getScreenXFromGLX(float glX){ return (int) (SCREEN_WIDTH * (glX) / GL_WIDTH); }
//	public int getScreenYFromGLY(float glY){ return (int) (SCREEN_HEIGHT - SCREEN_HEIGHT * (glY) / GL_HEIGHT); }
	public int getScreenYFromGLY(float glY){ return (int) (SCREEN_HEIGHT * (glY) / GL_HEIGHT); }

//	public void setGLWIDTH(float w){ GL_WIDTH = w; }
//	public void setGLHEIGHT(float h){ GL_HEIGHT = h; }
}